<!DOCTYPE html>
<html>
    <head>
        <title>MediaKeys.getStatusForPolicy</title>
        <script src="encrypted-media-utils.js"></script>
        <script src="../../resources/testharness.js"></script>
        <script src="../../resources/testharnessreport.js"></script>
    </head>
    <body>
        <script>
            promise_test(function(test)
            {
                var hdcpVersionNone = '';
                var hdcpVersion2_0 = '2.0';
                var mediaKeys;

                // Calls getStatusForPolicy() with |hdcpVersion| and expects it
                // to fail. If |expectedError| is specified, the resulting
                // error must match. If |expectedError| not specified, the
                // resulting error must be a NotSupportedError exception.
                function getStatusForHdcpPolicy(hdcpVersion, expectedError)
                {
                    return mediaKeys.getStatusForPolicy(hdcpVersion).then(function(MediaKeyStatus) {
                        // getStatusForPolicy() is not supported by Clear Key
                        // key system and the promise should always be rejected.
                        return Promise.reject('Promise resolved unexpectedly');
                    }, function(error) {
                        if (expectedError === undefined) {
                            assert_equals(error.name, 'NotSupportedError');
                        } else {
                            assert_equals(error, expectedError);
                        }
                        return Promise.resolve();
                    });
                };

                return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
                    return access.createMediaKeys();
                }).then(function(result) {
                    mediaKeys = result;
                    return getStatusForHdcpPolicy({});
                }).then(function() {
                    return getStatusForHdcpPolicy({minHdcpVersion: hdcpVersionNone});
                }).then(function() {
                    return getStatusForHdcpPolicy({minHdcpVersion: hdcpVersion2_0});
                }).then(function() {
                    return getStatusForHdcpPolicy({foo: 'bar'});
                }).then(function() {
                    return getStatusForHdcpPolicy(
                        { get minHdcpVersion() { return hdcpVersion2_0; } });
                }).then(function() {
                    return getStatusForHdcpPolicy(
                        { get minHdcpVersion() { throw 'throwing getter'; } },
                        'throwing getter');
                });
            }, 'MediaKeys.getStatusForPolicy');
        </script>
    </body>
</html>
